<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>JS - 1.7</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <script>
        function ajouterTirets () {
            var valeurChampTexte = document.formulaire.champTexte.value;
            var elementResultat = document.formulaire.champResultat;
            
            var nbreCaracteres = valeurChampTexte.length;
            
            var valeurResultat = " ";
            
            for(var x=0; x<nbreCaracteres; x++) {
                if(nbreCaracteres==x+1) { 
                    valeurResultat += valeurChampTexte.charAt(x);  
                }
                else {
                    valeurResultat += valeurChampTexte.charAt(x)+"-";  
                }         
            }
            elementResultat.value = valeurResultat;
        }    
        </script>
    </head>
    
    <body>
        <form name="formulaire">
            <input type="text" name="champTexte" value="">
            <input type="button" value="Ajouter des tirets entre chaque lettre" onclick="ajouterTirets();">
            <input type="text" name="champResultat" value="">
        </form>
    </body>
</html>
